<template>
<div class="">
<criteria partial='criteria' @show-con = "pocon" v-ref:cri>
  <div class= "form-horizontal" partial>
    <div class="col-sm-11">
      <label for="f_operat_type" class="col-sm-2 control-label">操作类型:</label>
      <div class="col-sm-2">
        <v-select id="f_operat_type"
        v-model="model.f_operat_type"
        placeholder='请选择'
        condition="t.f_operat_type ='{}'"
        :value.sync="model.f_operat_type"
        :options='$parent.operatType'
        close-on-select clear-button>
        </v-select>
      </div>
      <label for="f_state" class="col-sm-2 control-label">操作状态:</label>
      <div class="col-sm-2" >
        <v-select id="f_state"
        v-model="model.f_state"
        placeholder='请选择'
        condition="t.f_state ='{}'"
        :value.sync="model.f_state"
        :options='$parent.state'
        close-on-select clear-button>
        </v-select>
      </div>
    </div>
 </div>
 </criteria>
</div>
</template>
<script>
import AppData from '../../../../../stores/AppData'
export default {
  data () {
    return {
      arr: [],
      condition: ''
    }
  },
  methods: {
    reset () {
      this.$refs.cri.model.f_operat_type = ''
      this.$refs.cri.model.f_state = ''
    },
    pocon () {
      let model = this.$refs.cri.model
      this.arr = []
      this.addSelectElement(model.f_operat_type, '操作类型', 'f_operat_type')
      this.addSelectElement(model.f_state, '操作状态', 'f_state')
      this.$dispatch('showcond', this.arr)
    },
    addSelectElement (value, chineseColumn, englishColumn) {
      if (value && value.length > 0 && value[0] !== '') {
        this.arr.push({content: `${chineseColumn}:${value}`, culmn: englishColumn})
      }
    },
    sort () {
      for (let key in this.$refs.cri.model) {
        let num = 0
        for (let index in this.arr) {
          if (this.arr[index].culmn !== key) {
            num++
          }
        }
        if (num === (this.arr.length)) {
          this.$refs.cri.model[key] = ''
        }
      }
    }
  },
  watch: {
    'arr': {
      deep: true,
      handler (val) {
        this.sort()
        this.$refs.cri.search()
      }
    }
  },
  computed: {
    state () {
      return [{label: '全部', value: ''}, ...AppData.getParam('状态')]
    },
    operatType () {
      return [{label: '全部', value: ''}, ...AppData.getParam('操作类型')]
    }
  }
}
</script>
